﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PoXiao
{
    public partial class Form1 : Form
    {
        //------------------------------------------------------------------------------------------------------------------------
        //下面为基本环境变量
        //------------------------------------------------------------------------------------------------------------------------
        //static string baseUrl = "http://localhost:8087/poxiao-admin-dev";//dev环境
        //const string expBaseUrl = "http://poxiao.free.svipss.top/poxiao-admin"; //free环境
        const string vipBaseUrl = "http://poxiao2.fgimaxl2.vipnps.vip/poxiao-admin"; //vip环境
        static string baseUrl = "";
        static bool running = true;//能否运行
        static bool checkIsOkTask = true;//是否开启账号定时鉴权任务
        static bool isOk = false;//账号是否为会员
        static JObject userInfoObj = null;
        static string tokens = "";
        static string userNameParse = "";
        static string machineCode = MachineCode.GetMachineCodeString();//获取机器码
        static int versionCode = 1120;//本地版本号
        static string versionName = "v1.1.2";//本地版本名称
        static int couldVersionCode = 0;//云端版本号
        static string couldVersionName = "";//云端版本名称
        static int amount = 0;//成功次数
        static int failAmount = 0;//失败次数
        static int runNumber = 0;//设置运行次数
        static int failNumber = 0;//设置失败最大次数
        static int endResult = 0;//设置结束原因 0-自然结束 1-手动结束 2-失败结束
        static int bindModel = 0;
        static DateTime lastAmountTime = new DateTime();//最后一次成功的时间
        static DateTime lastFailAmountTime = new DateTime();//最后一次失败的时间
        bool bindStatus = false; //绑定状态 true-成功 false-失败
        string windowName = "窗口1";
        Dm.dmsoft dm = new Dm.dmsoft();        //实例化大漠

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);                //返回对应句柄窗口大小
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); //寻找对应名称的句柄
        [StructLayout(LayoutKind.Sequential)]
        public struct RECT        //窗口四个角坐标定义
        {
            public int Left;                             //最左坐标
            public int Top;                             //最上坐标
            public int Right;                           //最右坐标
            public int Bottom;                        //最下坐标
        }
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter,
            string lclassName, string windowTitle);        //寻找对应子窗口句柄
        public static Form1 form1;
        public Form1()
        {
            InitializeComponent();
            dm.SetPath("Resources");
            dm.SetDict(0, "dm_soft.txt");
            form1 = this;
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;//设置该属性 为false
            DmSoftRegister.AutoRegCom("regsvr32 -s dm.dll");
            userName.MaxLength = 18;
            passWord.MaxLength = 18;
            radioButton1.Checked = false;
            radioButton2.Checked = false;
            radioButton0.Checked = true;
            expChannel.Checked = true;
            vipChannel.Checked = false;
            functionCb.SelectedIndex = 0;
            bandwindowCb.SelectedIndex = 0;
            displayCb.SelectedIndex = 1;
            modelCb.SelectedIndex = 0;
            mouseCb.SelectedIndex = 1;
            bindsimulatorCb.SelectedIndex = 0;
            version.Text = versionName;
            form1.Text = "破晓" + " " + versionName;
        }
        //------------------------------------------------------------------------------------------------------------------------
        //下面为组件载入事件或点击按钮事件
        //------------------------------------------------------------------------------------------------------------------------
        private void Form1_Load(object sender, EventArgs e)//窗口载入时读取本地用户信息鉴权
        {
            baseUrl = vipBaseUrl;
            if (checkIsOkTask)
            {
                CheckIsOk.Quartz.Start().GetAwaiter().GetResult();//启动定时鉴权
            }
            //------------------------------------------------------------------------------------------------------------------------
            //版本检查
            //------------------------------------------------------------------------------------------------------------------------
            HttpHelper http = new HttpHelper();
            StringBuilder str = new StringBuilder(baseUrl);
            string url = str.Append("/version/getLastNewVersion?versionCode=" + versionCode).ToString();//注册接口
            string codeParse = "";
            HttpItem item = new HttpItem()
            {
                URL = url,
                Method = "get",
                Accept = "application/json, text/plain, */*",
                ContentType = "application/json;charset=UTF-8"
            };
            item.Header.Add("Accept-Encoding", "gzip, deflate, br");
            item.Header.Add("Accept-Language: zh-CN,zh;q=0.9");
            item.Header.Add("sec-ch-ua-platform: 'Windows'");
            //item.Header.Add("token: " + tokens.Trim());
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            codeParse = HttpHelper.JsonParse(html, "code");
            if (codeParse.Equals("200"))
            {
                int.TryParse(HttpHelper.JsonParse(html, "data", "versionCode"), out couldVersionCode);
                string forceType = HttpHelper.JsonParse(html, "data", "type");
                string downloadUrl = HttpHelper.JsonParse(html, "data", "downloadUrl");
                string content = HttpHelper.JsonParse(html, "data", "content");
                couldVersionName = HttpHelper.JsonParse(html, "data", "versionName");
                couldversionLebal.Text = couldVersionName;
                if (forceType.Equals("0") && versionCode < couldVersionCode)
                {
                    DialogResult res = MessageBox.Show("最新云端版本为： " + couldVersionName + "\n\r更新内容：" + content, "有新版本！是否更新", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (res == DialogResult.Yes)
                    {
                        System.Diagnostics.Process.Start(downloadUrl);
                        System.Environment.Exit(0);
                    }

                }
                else if (forceType.Equals("1") && versionCode < couldVersionCode)
                {
                    MessageBox.Show("最新云端版本为： " + couldVersionName + " (此版本不更新将无法使用) \n\r更新内容：" + content, "有新版本！", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    System.Diagnostics.Process.Start(downloadUrl);
                    System.Environment.Exit(0);
                }
            }
            else if (!codeParse.Equals("") && !codeParse.Equals("200"))
            {
                MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
                System.Environment.Exit(0);
            }
            else if (codeParse.Equals(""))
            {
                MessageBox.Show("网络异常！");
                System.Environment.Exit(0);
            }
            //------------------------------------------------------------------------------------------------------------------------

            string userInfo = System.Windows.Forms.Application.StartupPath + "\\userInfo.txt";
            if (File.Exists(userInfo) && !string.IsNullOrEmpty(File.ReadAllText(userInfo)))  // 判断是否已有相同文件 
            {
                userInfoObj = JsonConvert.DeserializeObject<JObject>(TextEncryptUtils.AesDecrypt(File.ReadAllText(userInfo), "wssf@424544341234567890123456789"));
            }
            if (null != userInfoObj)
            {
                string userTypeParse = HttpHelper.JObjectParse(userInfoObj, "data", "userType");
                string secretKeyParse = HttpHelper.JObjectParse(userInfoObj, "data", "secretKey");
                string expirationTimeStrParse = HttpHelper.JObjectParse(userInfoObj, "data", "expirationTimeStr");
                string requestTimeParse = HttpHelper.JObjectParse(userInfoObj, "data", "requestTime");
                tokens = HttpHelper.JObjectParse(userInfoObj, "data", "token");
                userNameParse = HttpHelper.JObjectParse(userInfoObj, "data", "userName");
                accountLabel.Text = userNameParse;
                ETimeLabel.Text = expirationTimeStrParse;
                switch (userTypeParse)
                {
                    case "0":
                        userTypeLabel.Text = "注册会员";
                        isOk = false;
                        break;
                    case "1":
                        userTypeLabel.Text = "VIP会员";
                        isOk = true;
                        vipChannel.Checked = true;
                        baseUrl = vipBaseUrl;
                        break;
                    case "2":
                        userTypeLabel.Text = "永久会员";
                        isOk = true;
                        vipChannel.Checked = true;
                        baseUrl = vipBaseUrl;
                        break;
                    default:
                        break;
                }
            }
        }

        private void bindBt_Click(object sender, EventArgs e)//绑定模拟器窗口
        {
            int hwnd1 = 0;
            int hwnd2 = 0;
            int model = 0;
            IntPtr hWnd2 ;
           int.TryParse(modelCb.Text, out model);
            if (bindsimulatorCb.SelectedIndex == 0)
            {
                windowName = bandwindowCb.Text;//获得要绑定窗口的名称
            }
            else if (bindsimulatorCb.SelectedIndex == 1) {

                windowName = bandwindowCb.Text+"(64)";//雷电5

            }
            else if (bindsimulatorCb.SelectedIndex == 2)
            {
                windowName = "阴阳师 - MuMu模拟器";//mumu
            }
            /**
             * 以下是检查绑定窗口大小的代码
             * 
             * */
            IntPtr hWnd = FindWindow(null, windowName);
            if (bindsimulatorCb.SelectedIndex == 2)
            {
                hWnd2 = FindWindowEx(hWnd, IntPtr.Zero, "Qt5152QWindowIcon", "NemuPlayer");
            }
            else { 
                hWnd2 = FindWindowEx(hWnd, IntPtr.Zero, "RenderWindow", "TheRender");
            }
            RECT rc = new RECT();
            GetWindowRect(hWnd2, ref rc);
            int width = rc.Right - rc.Left;//窗口的宽度                       
            int height = rc.Bottom - rc.Top;//窗口的高度
            if (hWnd.ToString().Equals("0"))
            {
                MessageBox.Show("请检查模拟器是否为雷电模拟器，命名是否为：" + windowName, "窗口绑定失败！",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (0 != width && 0 != height)
                {
                    label7.Text = "宽：" + width;
                    label8.Text = "高：" + height;

                }
                if (960 == width && 540 == height)
                {
                    /**
                    * 以下是大漠绑定窗口的代码
                    * 
                    * */
                    try {

                        if (bindsimulatorCb.SelectedIndex == 2)
                        {
                            hwnd1 = dm.FindWindow("Qt5152QWindowIcon", windowName);
                            hwnd2 = dm.FindWindowEx(hwnd1, "Qt5152QWindowIcon", "NemuPlayer");
                        }
                        else
                        {
                            hwnd1 = dm.FindWindow("LDPlayerMainFrame", windowName);
                            hwnd2 = dm.FindWindowEx(hwnd1, "RenderWindow", "TheRender");
                        }
                        bindModel = dm.BindWindow(hwnd2, displayCb.Text, mouseCb.Text, "windows", model);//绑定
                    }
                    catch (Exception ex){
                        return;
                    }
                    if (0 == bindModel)
                    {
                        MessageBox.Show("请检查模拟器是否加载完毕或者使用了杀毒软件！", windowName+"窗口绑定失败！", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        bindStatus = true;
                        pictureBox1.Image = Properties.Resources.zhengque;
                        notice.Text = "绑定窗口成功！";
                        if (bindBt.Text.Equals("重新绑定"))
                        {
                            MessageBox.Show("重新绑定" + bandwindowCb.Text + "成功！");
                        }
                        bindBt.Text = "重新绑定";
                    }
                }
                else
                {
                    pictureBox1.Image = Properties.Resources.cuowu;
                    MessageBox.Show("请检查窗口大小是否为宽:960，高:540，dpi:160", "窗口大小不符合规范！",
                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }

        private async void runBt_Click(object sender, EventArgs e)//运行按钮
        {
            running = true;
            object x = new object();
            object y = new object();
            int taskId = functionCb.SelectedIndex;//任务id
            int rId = 0; //角色id 0-单人 1-队员 2-队长
            int.TryParse(runNum.Text, out runNumber);
            int.TryParse(failNum.Text, out failNumber);
            bool role0 = radioButton0.Checked;
            bool role1 = radioButton1.Checked;
            bool role2 = radioButton2.Checked;
            if (role1 == true)
            {
                rId = 1;
            }
            else if (role2 == true)
            {
                rId = 2;
            }
            else if (role0 == true)
            {
                rId = 0;
            }


            if (bindStatus && isOk)
            {
                switch (taskId)
                {
                    case 0:
                        runBt.Enabled = false;
                        Task<int> task0 = new Task<int>(() => { yuhun(rId, x, y); return 0; });
                        task0.Start();
                        await task0;
                        runBt.Enabled = true;
                        end();
                        break;
                    case 1:
                        runBt.Enabled = false;
                        Task<int> task1 = new Task<int>(() => { yulin(x, y); return 0; });
                        task1.Start();
                        await task1;
                        runBt.Enabled = true;
                        end();
                        break;
                    case 4:
                        runBt.Enabled = false;
                        Task<int> task4 = new Task<int>(() => { yeyuanhuo(x, y); return 0; });
                        task4.Start();
                        await task4;
                        runBt.Enabled = true;
                        end();
                        break;
                    case 5:
                            runBt.Enabled = false;
                            Task<int> task5 = new Task<int>(() => { juexing(rId, x, y); return 0; });
                            task5.Start();
                            await task5;
                            runBt.Enabled = true;
                            end();
                        break;
                    default:
                        break;
                }
            }
            else if (!bindStatus)
            {
                MessageBox.Show("请先绑定窗口");
            }
            else if (!isOk)
            {
                MessageBox.Show("会员信息已过期或失效，请重新登录！");
            }
        }

        private void manualEndBt_Click(object sender, EventArgs e)//手动结束按钮
        {
            endResult = 1;
            running = false;
        }

        private void linkHowToUse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)//打开使用文档按钮
        {
            System.Diagnostics.Process.Start("https://shimo.im/docs/HvvjRkGgx6htWXyh");
        }
        private void qunlinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start("https://jq.qq.com/?_wv=1027&k=FjabfNaz");
        }
        private void registerBt_Click(object sender, EventArgs e)//注册按钮
        {
            emailLabel.Visible = true;
            email.Visible = true;
            bool flagRegister = true;
            Regex re = new Regex(@"^[A-Za-z0-9]{6,18}$");
            Regex pwRe = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9]{6,18}$");
            Regex emailRe = new Regex(@"^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$");
            if (!re.IsMatch(userName.Text))
            {
                flagRegister = false;
                MessageBox.Show("用户名只能为6-18位的字母、数字和下划线组成！");
            }
            else if (!pwRe.IsMatch(passWord.Text))
            {
                flagRegister = false;
                MessageBox.Show("密码只能为6-18位的字母、数字和特殊符号组成！");
            }
            else if (!emailRe.IsMatch(email.Text))
            {
                flagRegister = false;
                MessageBox.Show("邮箱格式错误");
            }

            if (flagRegister)
            {
                HttpHelper http = new HttpHelper();
                StringBuilder str = new StringBuilder(baseUrl);
                string url = str.Append("/user/register").ToString();//注册接口
                string codeParse = "";
                var data = new { userName = userName.Text, passWord = passWord.Text, machineCode = machineCode, email = email.Text };
                string json = JsonConvert.SerializeObject(data);
                HttpItem item = new HttpItem()
                {
                    URL = url,
                    Method = "post",
                    Accept = "application/json, text/plain, */*",
                    Postdata = json,
                    ContentType = "application/json;charset=UTF-8"
                };
                item.Header.Add("Accept-Encoding", "gzip, deflate, br");
                item.Header.Add("Accept-Language: zh-CN,zh;q=0.9");
                item.Header.Add("sec-ch-ua-platform: 'Windows'");
                //item.Header.Add("token: " + tokens.Trim());
                HttpResult result = http.GetHtml(item);
                string html = result.Html;
                codeParse = HttpHelper.JsonParse(html, "code");
                if (codeParse.Equals("200"))
                {
                    MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
                }
                else if (!codeParse.Equals("") && !codeParse.Equals("200"))
                {
                    MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
                }
                else if (codeParse.Equals(""))
                {
                    MessageBox.Show("网络异常，请联系管理员！");

                }
            }
        }

        private void loginBt_Click(object sender, EventArgs e)//登录按钮
        {
            StringBuilder str = new StringBuilder(baseUrl);
            string url = str.Append("/user/login").ToString();//登录接口
            HttpHelper http = new HttpHelper();
            var data = new { userName = userName.Text, passWord = passWord.Text, machineCode = machineCode };
            string json = JsonConvert.SerializeObject(data);
            HttpItem item = new HttpItem()
            {
                URL = url,
                Method = "post",
                Accept = "application/json, text/plain, */*",
                Postdata = json,
                ContentType = "application/json;charset=UTF-8"
            };
            item.Header.Add("Accept-Encoding", "gzip, deflate, br");
            item.Header.Add("Accept-Language: zh-CN,zh;q=0.9");
            item.Header.Add("sec-ch-ua-platform: 'Windows'");
            //item.Header.Add("token: " + tokens.Trim());
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            string codeParse = "";
            string userTypeParse = "";
            string secretKeyParse = "";
            string expirationTimeStrParse = "";
            string requestTimeParse = "";
            codeParse = HttpHelper.JsonParse(html, "code");
            if (codeParse.Equals("200"))
            {
                userNameParse = HttpHelper.JsonParse(html, "data", "userName");
                tokens = HttpHelper.JsonParse(html, "data", "token");
                userTypeParse = HttpHelper.JsonParse(html, "data", "userType");
                secretKeyParse = HttpHelper.JsonParse(html, "data", "secretKey");
                expirationTimeStrParse = HttpHelper.JsonParse(html, "data", "expirationTimeStr");
                requestTimeParse = HttpHelper.JsonParse(html, "data", "requestTime");
                accountLabel.Text = userNameParse;
                ETimeLabel.Text = expirationTimeStrParse;
                switch (userTypeParse)
                {
                    case "0":
                        userTypeLabel.Text = "注册会员";
                        isOk = false;
                        break;
                    case "1":
                        userTypeLabel.Text = "VIP会员";
                        isOk = true;
                        break;
                    case "2":
                        userTypeLabel.Text = "永久会员";
                        isOk = true;
                        break;
                    default:
                        break;
                }
                JObject obj = JObject.Parse(html);
                string userInfo = System.Windows.Forms.Application.StartupPath + "\\userInfo.txt";
                if (!File.Exists(userInfo))  // 判断是否已有相同文件 
                {
                    FileStream fs = new FileStream(userInfo, FileMode.Create, FileAccess.ReadWrite);
                    fs.Close();
                }
                File.WriteAllText(userInfo, TextEncryptUtils.AesEncrypt(JsonConvert.SerializeObject(obj).ToString(), "wssf@424544341234567890123456789"));
                MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
            }
            else if (!codeParse.Equals("") && !codeParse.Equals("200"))
            {
                MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
            }
            else
            {
                MessageBox.Show("网络异常，请联系管理员！");
            }
        }

        private void rechargeBt_Click(object sender, EventArgs e)//充值按钮
        {
            StringBuilder str = new StringBuilder(baseUrl);
            string codeParse = "";
            string url = str.Append("/user/useCode" + "?userName=" + chargeUserName.Text.Trim() + "&code=" + vipCode.Text.Trim()).ToString();//充值接口
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = url,
                Method = "post",
                Accept = "application/json, text/plain, */*",
                ContentType = "application/x-www-form-urlencoded"
            };
            item.Header.Add("Accept-Encoding", "gzip, deflate, br");
            item.Header.Add("Accept-Language: zh-CN,zh;q=0.9");
            item.Header.Add("sec-ch-ua-platform: 'Windows'");
            //item.Header.Add("token: " + tokens.Trim());
            HttpResult result = http.GetHtml(item);
            string html = result.Html;
            codeParse = HttpHelper.JsonParse(html, "code");
            if (codeParse.Equals("200"))
            {
                MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
            }
            else if (!codeParse.Equals("") && !codeParse.Equals("200"))
            {

                MessageBox.Show(HttpHelper.JsonParse(html, "msg"));
            }
            else if (codeParse.Equals(""))
            {
                MessageBox.Show("网络异常，请联系管理员！");

            }
        }

        private void Capturer_Click(object sender, EventArgs e)
        {
            if (1 == bindModel)
            {
                int a; int b; int c; int d;
                string timeNow = DateTime.Now.ToLocalTime().ToString().Replace(" ", "").Replace("/", "").Replace(":", "");
                string s = "a调试截图"+timeNow + ".bmp";
                int.TryParse(x1.Text, out a);
                int.TryParse(y1.Text, out b);
                int.TryParse(x2.Text, out c);
                int.TryParse(y2.Text, out d);
                dm.Capture(a, b, c, d, s);
                System.Diagnostics.Process.Start("explorer.exe", "Resources");
            }
            else
            {
                MessageBox.Show("请先绑定模拟器！");
            }
        }

        private void switchbT_Click(object sender, EventArgs e)
        {
            if (expChannel.Checked)
            {
                baseUrl = vipBaseUrl;
                if (baseUrl.Equals("http://poxiao.free.svipss.top/poxiao-admin")) {
                    MessageBox.Show("切换成功！");
                }
                else
                {
                    MessageBox.Show("发生错误，切换失败！");
                }
            }
            else if (isOk && vipChannel.Checked) {
                baseUrl = vipBaseUrl;
                if (baseUrl.Equals("http://poxiao2.fgimaxl2.vipnps.vip/poxiao-admin"))
                {
                    MessageBox.Show("切换成功！");
                }
                else {
                    MessageBox.Show("发生错误，切换失败！");
                }
            }
            else if (!isOk)
            {
                MessageBox.Show("您还不是会员哦，无法切换！");
                expChannel.Checked = true;
            }
        }
        //------------------------------------------------------------------------------------------------------------------------
        //下面为限制输入框字符具体方法
        //------------------------------------------------------------------------------------------------------------------------
        private void userName_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.userName.ImeMode = ImeMode.Off;

            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
                  (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || (e.KeyChar == '_') || (e.KeyChar.GetHashCode() == 1441814))
            {
                e.Handled = false;
            }

            else
            {
                e.Handled = true;
            }
        }

        private void passWord_KeyPress(object sender, KeyPressEventArgs e)
        {

            this.passWord.ImeMode = ImeMode.Off;

            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
                  (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || (e.KeyChar == '_') || (e.KeyChar == '@') || (e.KeyChar == '.') || (e.KeyChar == '/') || (e.KeyChar == '?') ||
                  (e.KeyChar == '&') || (e.KeyChar == '=') || (e.KeyChar == '^') || (e.KeyChar == '%') || (e.KeyChar == '!'))
            {
                e.Handled = false;
            }

            else
            {
                e.Handled = true;
            }
        }

        private void email_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.email.ImeMode = ImeMode.Off;

            if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (e.KeyChar >= 'A' && e.KeyChar <= 'Z') ||
                  (e.KeyChar >= 'a' && e.KeyChar <= 'z') || (e.KeyChar == 8) || (e.KeyChar == '@') || (e.KeyChar == '.'))
            {
                e.Handled = false;
            }

            else
            {
                e.Handled = true;
            }
        }

        private void executionsNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            this.runNum.ImeMode = ImeMode.Off;
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }

        private void userName_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                userName.ContextMenu = new ContextMenu();
            }
        }

        private void passWord_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                userName.ContextMenu = new ContextMenu();
            }
        }

        private void email_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                userName.ContextMenu = new ContextMenu();
            }
        }

        //------------------------------------------------------------------------------------------------------------------------
        //下面为脚本具体实现方法
        //------------------------------------------------------------------------------------------------------------------------
        //1.御魂实现方法
        public void yuhun(int rId, object x, object y)
        {
            Random ran = new Random();
            int rk = ran.Next(0, 9);
            int rk1 = ran.Next(0, 3);
            int rkx2 = ran.Next(0, 73);
            int rky2 = ran.Next(0, 46);
            int rkx3 = ran.Next(0, 67);
            int rky3 = ran.Next(0, 53);
            int RandX = ran.Next(0, 451);
            int RandY = ran.Next(0, 136);
            int RandX2 = ran.Next(0, 507);
            int RandY2 = ran.Next(0, 109);
            int RandX3 = ran.Next(0, 900);
            int RandY3 = ran.Next(0, 75);
            switch (rId)
            {
                case 0:
                    if (0 == runNumber)
                    {
                        do
                        {
                            //点击挑战
                            dm.FindStr(843, 459, 892, 483, "挑战", "b@e5dcc4-303030|a48866-000000|a49371-000000|a59473-000000", 0.9, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(834 + rkx3, 453 + rky3);
                                dm.LeftClick();
                                notice.Text = "点击挑战中...";
                                Thread.Sleep(150);
                            }
                            else {
                                dm.FindPic(832, 447, 902, 507, "魂土挑战.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(834 + rkx3, 453 + rky3);
                                    dm.LeftClick();
                                    notice.Text = "点击挑战中...";
                                    Thread.Sleep(150);
                                }

                            }
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.9, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            dm.FindPic(303, 90, 403, 175, "失败太鼓图1.bmp|失败太鼓图.bmp|失败太鼓图3.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            // 奖励结算
                            dm.FindPic(410, 372, 531, 441, "宝箱5.bmp|宝箱6.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);
                                success();
                            }
                            else
                            {
                                dm.FindPic(286, 419, 325, 454, "数据图2.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(447 + RandX2, 425 + RandY2);
                                    dm.LeftClick();
                                    notice.Text = "领取奖励中！...";
                                    Thread.Sleep(150);
                                    success();
                                }
                            }
                            failEnd();
                        }while (running && isOk);

                    } else if (0 < runNumber) {

                        do
                        {
                            //点击挑战
                            dm.FindStr(843, 459, 892, 483, "挑战", "b@e5dcc4-303030|a48866-000000|a49371-000000|a59473-000000", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(834 + rkx3, 453 + rky3);
                                dm.LeftClick();
                                notice.Text = "点击挑战中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(832, 447, 902, 507, "魂土挑战.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(834 + rkx3, 453 + rky3);
                                    dm.LeftClick();
                                    notice.Text = "点击挑战中...";
                                    Thread.Sleep(150);
                                }
                            }
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            dm.FindPic(303, 90, 403, 175, "失败太鼓图1.bmp|失败太鼓图.bmp|失败太鼓图3.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            // 奖励结算
                            dm.FindPic(410, 372, 531, 441, "宝箱5.bmp|宝箱6.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);
                                success();
                            }
                            else
                            {
                                dm.FindPic(286, 419, 325, 454, "数据图2.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(447 + RandX2, 425 + RandY2);
                                    dm.LeftClick();
                                    notice.Text = "领取奖励中！...";
                                    Thread.Sleep(150);
                                    success();
                                }
                            }
                            autoEnd();
                            failEnd();
                        } while (running && isOk);

                    }
                break;
                case 2:
                    if (0 == runNumber)
                    {
                        do
                        {
                            //默认邀请队友
                            dm.FindStr(435, 247, 594, 293, "默认邀请队友", "453f37-505050|2a2722-505050|9d8d7b-000000|988876-000000|ac9a86-000000|a2917e-000000", 0.9, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.FindPic(403, 250, 438, 290, "勾选.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(416 + rk, 265 + rk);
                                    dm.LeftClick();
                                }
                                dm.FindPic(403, 250, 438, 290, "已勾选.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.FindStr(520, 310, 624, 338, "确定", "453f37-606060", 0.9, out x, out y);
                                    if ((int)x > 0 && (int)y > 0)
                                    {
                                        dm.MoveTo((int)x, (int)y);
                                        dm.LeftClick();
                                        notice.Text = "默认邀请队友...";
                                    }
                                }
                                Thread.Sleep(150);
                            }
                            //不接协作
                            dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x, (int)y);
                                dm.LeftClick();
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo((int)x, (int)y);
                                    dm.LeftClick();
                                    Thread.Sleep(150);
                                }
                            }
                            //点击挑战
                            dm.FindPic(874, 444, 954, 514, "挑战.bmp|挑战2.bmp|挑战3.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x + rk1, (int)y + rk1);
                                dm.LeftClick();
                                notice.Text = "点击挑战中...";
                                Thread.Sleep(150);
                            }
                            Thread.Sleep(150);
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp|太鼓图3.bmp|太鼓图4.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(460, 410, 499, 449, "点赞.bmp|点赞2.bmp|点赞3.bmp|点赞4.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(503 + RandX, 400 + RandY);
                                    dm.LeftClick();
                                    notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                    Thread.Sleep(150);
                                }
                            }
                            dm.FindPic(299, 45, 402, 140, "失败太鼓图.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            dm.FindPic(301, 49, 405, 137, "失败太鼓图2.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.FindStr(475, 205, 517, 248, "继续", "b@cbb59e-303030", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.FindStr(525, 310, 616, 336, "确定", "b@f4b25f-404040", 0.9, out x, out y);
                                    if ((int)x > 0 && (int)y > 0)
                                    {
                                        dm.MoveTo((int)x, (int)y);
                                        dm.LeftClick();
                                        notice.Text = "继续邀请好友";
                                        Thread.Sleep(150);
                                    }
                                }
                            }
                            // 奖励结算
                            dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp|宝箱7.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);
                                success();
                            }
                            else
                            {
                                dm.FindPic(38, 474, 79, 514, "数据图3.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(447 + RandX2, 425 + RandY2);
                                    dm.LeftClick();
                                    notice.Text = "领取奖励中！...";
                                    Thread.Sleep(150);
                                    success();
                                }
                            }
                            failEnd();
                        } while (running && isOk);

                    }
                    else if (0 < runNumber)
                    {
                        do
                        {
                            //默认邀请队友
                            dm.FindStr(435, 247, 594, 293, "默认邀请队友", "453f37-505050|2a2722-505050|9d8d7b-000000|988876-000000|ac9a86-000000|a2917e-000000", 0.9, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.FindPic(403, 250, 438, 290, "勾选.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(416 + rk, 265 + rk);
                                    dm.LeftClick();
                                }
                                dm.FindPic(403, 250, 438, 290, "已勾选.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.FindStr(520, 310, 624, 338, "确定", "453f37-606060", 0.9, out x, out y);
                                    if ((int)x > 0 && (int)y > 0)
                                    {
                                        dm.MoveTo((int)x, (int)y);
                                        dm.LeftClick();
                                        notice.Text = "默认邀请队友...";
                                    }
                                }
                                Thread.Sleep(150);
                            }
                            //不接协作
                            dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x, (int)y);
                                dm.LeftClick();
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo((int)x, (int)y);
                                    dm.LeftClick();
                                    Thread.Sleep(150);
                                }
                            }
                            //点击挑战
                            dm.FindPic(874, 444, 954, 514, "挑战.bmp|挑战2.bmp|挑战3.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x + rk1, (int)y + rk1);
                                dm.LeftClick();
                                notice.Text = "点击挑战中...";
                                Thread.Sleep(150);
                            }
                            Thread.Sleep(150);
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp|太鼓图3.bmp|太鼓图4.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(460, 410, 499, 449, "点赞.bmp|点赞2.bmp|点赞3.bmp|点赞4.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(503 + RandX, 400 + RandY);
                                    dm.LeftClick();
                                    notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                    Thread.Sleep(150);
                                }
                            }
                            dm.FindPic(299, 45, 402, 140, "失败太鼓图.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            dm.FindPic(301, 49, 405, 137, "失败太鼓图2.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.FindStr(475, 205, 517, 248, "继续", "b@cbb59e-303030", 0.8, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.FindStr(525, 310, 616, 336, "确定", "b@f4b25f-404040", 0.8, out x, out y);
                                    if ((int)x > 0 && (int)y > 0)
                                    {
                                        dm.MoveTo((int)x, (int)y);
                                        dm.LeftClick();
                                        notice.Text = "继续邀请好友";
                                        Thread.Sleep(150);
                                    }
                                }
                            }
                            // 奖励结算
                            dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp|宝箱7.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);
                                success();
                            }
                            else
                            {
                                dm.FindPic(38, 474, 79, 514, "数据图3.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(447 + RandX2, 425 + RandY2);
                                    dm.LeftClick();
                                    notice.Text = "领取奖励中！...";
                                    Thread.Sleep(150);
                                    success();
                                }
                            }
                            autoEnd();
                            failEnd();
                        } while (running && isOk);
                    }
                    break;
                case 1:
                    if (0 == runNumber)
                    {
                        do
                        {
                            //默认接受邀请
                            dm.FindPic(148, 162, 206, 223, "默认接受邀请.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {

                                dm.FindStr(282, 187, 330, 216, "悲鸣", "a2463c-303030|c69086-101010|a75046-303030", 0.8, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(168, 186);
                                    dm.LeftClick();
                                    notice.Text = "默认接受邀请";
                                    Thread.Sleep(150);
                                }
                            }
                            else {
                                dm.FindPic(78, 163, 134, 221, "接受邀请.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {

                                    dm.FindStr(214, 190, 256, 214, "悲鸣", "a2463c-303030|c69086-101010|a75046-303030", 0.8, out x, out y);
                                    if ((int)x > 0 && (int)y > 0)
                                    {
                                        dm.MoveTo(103, 192);
                                        dm.LeftClick();
                                        notice.Text = "接受邀请";
                                        Thread.Sleep(150);
                                    }
                                }
                            }  
                            //不接协作
                            dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x, (int)y);
                                dm.LeftClick();
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo((int)x, (int)y);
                                    dm.LeftClick();
                                    Thread.Sleep(150);
                                }
                            }
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp|太鼓图3.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(460, 410, 499, 449, "点赞.bmp|点赞2.bmp|点赞3.bmp|点赞3.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(503 + RandX, 400 + RandY);
                                    dm.LeftClick();
                                    notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                    Thread.Sleep(150);
                                }
                            }
                            dm.FindPic(299, 45, 402, 140, "失败太鼓图.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            // 奖励结算
                            dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp|宝箱7.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);
                                success();
                            }
                            else {
                                dm.FindPic(38, 474, 79, 514, "数据图3.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(447 + RandX2, 425 + RandY2);
                                    dm.LeftClick();
                                    notice.Text = "领取奖励中！...";
                                    Thread.Sleep(150);
                                    success();
                                }
                            }
                            failEnd();
                        } while (running && isOk);
                    }
                    else if (0 < runNumber)
                    {
                        do
                        {
                            //默认接受邀请
                            dm.FindPic(148, 162, 206, 223, "默认接受邀请.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {

                                dm.FindStr(282, 187, 330, 216, "悲鸣", "a2463c-303030|c69086-101010|a75046-303030", 0.8, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(168, 186);
                                    dm.LeftClick();
                                    notice.Text = "默认接受邀请";
                                    Thread.Sleep(150);
                                }
                            }
                            else
                            {
                                dm.FindPic(78, 163, 134, 221, "接受邀请.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {

                                    dm.FindStr(214, 190, 256, 214, "悲鸣", "a2463c-303030|c69086-101010|a75046-303030", 0.8, out x, out y);
                                    if ((int)x > 0 && (int)y > 0)
                                    {
                                        dm.MoveTo(103, 192);
                                        dm.LeftClick();
                                        notice.Text = "接受邀请";
                                        Thread.Sleep(150);
                                    }
                                }
                            }
                            //不接协作
                            dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x, (int)y);
                                dm.LeftClick();
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo((int)x, (int)y);
                                    dm.LeftClick();
                                    Thread.Sleep(150);
                                }
                            }
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp|太鼓图3.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(460, 410, 499, 449, "点赞.bmp|点赞2.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(503 + RandX, 400 + RandY);
                                    dm.LeftClick();
                                    notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                    Thread.Sleep(150);
                                }
                            }
                            dm.FindPic(287, 84, 409, 181, "失败太鼓图.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            // 奖励结算
                            dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp|宝箱7.bmp", "000000", 0.8, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);                               
                                success();
                            }
                            else
                            {
                                dm.FindPic(38, 474, 79, 514, "数据图3.bmp", "000000", 0.8, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(447 + RandX2, 425 + RandY2);
                                    dm.LeftClick();
                                    notice.Text = "领取奖励中！...";
                                    Thread.Sleep(150);
                                    success();
                                }
                            }
                            autoEnd();
                            failEnd();
                        } while (running && isOk);
                    }
                    break;
                default:
                    break;

            }
        }
        //2.御灵实现方法
        public void yulin(object x, object y)
        {
            Random ran = new Random();
            int RandX = ran.Next(0, 84);
            int RandY = ran.Next(0, 54);
            int RandX1 = ran.Next(0, 620);
            int RandY1 = ran.Next(0, 125);
            int RandX2 = ran.Next(0, 60);
            int RandY2 = ran.Next(0, 60);
            if (0 == runNumber)
            {
                do
                {
                    //不接协作
                    dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo((int)x, (int)y);
                        dm.LeftClick();
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo((int)x, (int)y);
                            dm.LeftClick();
                            Thread.Sleep(150);
                        }
                    }
                    //点击挑战
                    dm.FindStr(721, 389, 915, 525, "挑战", "b@e7d9c3-303030|b39980-303030", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(818 + RandX, 448 + RandY);
                        dm.LeftClick();
                        notice.Text = "点击挑战中...";
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindPic(721, 389, 915, 525, "御灵挑战.bmp", "000000", 0.9, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(818 + RandX, 448 + RandY);
                            dm.LeftClick();
                            notice.Text = "点击挑战中...";
                            Thread.Sleep(150);
                        }
                    }
                    //点击准备
                    dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(840 + RandX2, 414 + RandY2);
                        dm.LeftClick();
                        notice.Text = "点击准备中...";
                        Thread.Sleep(150);
                    }
                    // 检查是否在战斗中
                    dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.86, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                        Thread.Sleep(150);
                    }
                    // 胜利|失败过场
                    dm.FindStr(55, 408, 99, 441, "本", "b@080a0c-303030|090a0b-303030", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        dm.MoveTo(336 + RandX1, 404 + RandY1);
                        dm.LeftClick();
                        notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindStr(55, 408, 99, 441, "次", "b@080a0c-303030|090a0b-303030", 0.9, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            int amount1 = amount + 1;
                            dm.MoveTo(336 + RandX1, 404 + RandY1);
                            dm.LeftClick();
                            notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                            Thread.Sleep(150);
                        }
                        else
                        {
                            dm.FindPic(312, 59, 409, 140, "太鼓图.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(336 + RandX1, 404 + RandY1);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                        }

                    }
                    dm.FindPic(287, 84, 409, 181, "失败太鼓图.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(30, 466);
                        dm.LeftClick();
                        notice.Text = "战斗失败！";
                        Thread.Sleep(150);
                        fail();
                    }
                    // 奖励结算
                    dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(336 + RandX1, 404 + RandY1);
                        dm.LeftClick();
                        success();
                        notice.Text = "领取奖励中！...";
                        Thread.Sleep(150);
                    }
                    failEnd();
                } while (running && isOk);
            }
            else if (0 < runNumber)
            {
                do
                {
                    //不接协作
                    dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo((int)x, (int)y);
                        dm.LeftClick();
                        Thread.Sleep(150);
                    }
                    //点击挑战
                    dm.FindStr(721, 389, 915, 525, "挑战", "b@e7d9c3-303030|b39980-303030", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(818 + RandX, 448 + RandY);
                        dm.LeftClick();
                        notice.Text = "点击挑战中...";
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindPic(721, 389, 915, 525, "御灵挑战.bmp", "000000", 0.9, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(818 + RandX, 448 + RandY);
                            dm.LeftClick();
                            notice.Text = "点击挑战中...";
                            Thread.Sleep(150);
                        }
                    }
                    //点击准备
                    dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(840 + RandX2, 414 + RandY2);
                        dm.LeftClick();
                        notice.Text = "点击准备中...";
                        Thread.Sleep(150);
                    }
                    // 检查是否在战斗中
                    dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.86, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                        Thread.Sleep(150);
                    }
                    // 胜利|失败过场
                    dm.FindStr(55, 408, 99, 441, "本", "b@080a0c-303030|090a0b-303030", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        dm.MoveTo(336 + RandX1, 404 + RandY1);
                        dm.LeftClick();
                        notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindStr(55, 408, 99, 441, "次", "b@080a0c-303030|090a0b-303030", 0.9, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            int amount1 = amount + 1;
                            dm.MoveTo(336 + RandX1, 404 + RandY1);
                            dm.LeftClick();
                            notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                            Thread.Sleep(150);
                        }
                        else
                        {
                            dm.FindPic(312, 59, 409, 140, "太鼓图.bmp|太鼓图2.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(336 + RandX1, 404 + RandY1);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                        }

                    }
                    dm.FindPic(287, 84, 409, 181, "失败太鼓图.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(30, 466);
                        dm.LeftClick();
                        notice.Text = "战斗失败！";
                        Thread.Sleep(150);
                        fail();
                    }
                    // 奖励结算
                    dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(336 + RandX1, 404 + RandY1);
                        dm.LeftClick();
                        success();
                        notice.Text = "领取奖励中！...";
                        Thread.Sleep(150);
                    }
                    autoEnd();
                    failEnd();
                } while (running && isOk);
            }
        }
        //3.业原火实现方法
        public void yeyuanhuo(object x, object y)
        {
            Random ran = new Random();
            int RandX = ran.Next(0, 70);
            int RandY = ran.Next(0, 70);
            int RandX1 = ran.Next(0, 620);
            int RandY1 = ran.Next(0, 125);
            int RandX2 = ran.Next(0, 60);
            int RandY2 = ran.Next(0, 60);
            if (0 == runNumber)
            {
                do
                {
                    //不接协作
                    dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo((int)x, (int)y);
                        dm.LeftClick();
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo((int)x, (int)y);
                            dm.LeftClick();
                            Thread.Sleep(150);
                        }
                    }
                    //点击挑战
                    dm.FindStr(840, 455, 897, 485, "挑战", "b@dbd1b9-404040|552200-000000|d39c53-000000|aa8629-000000|9e7822-000000|f1c87d-000000|d0ae46-000000|9f6c06-000000|a7896b-101010|a49270-000000", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(823 + RandX, 441 + RandY);
                        dm.LeftClick();
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindPic(840, 451, 896, 508, "业原火-痴.bmp", "000000", 0.9, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(823 + RandX, 441 + RandY);
                            dm.LeftClick();
                            Thread.Sleep(150);
                        }
                    }
                    //点击准备
                    dm.FindStr(844, 417, 920, 463, "准备", "b@dbd1b9-404040|e8d0a6-303030", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(840 + RandX2, 414 + RandY2);
                        dm.LeftClick();
                        notice.Text = "点击准备中...";
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(840 + RandX2, 414 + RandY2);
                            dm.LeftClick();
                            notice.Text = "点击准备中...";
                            Thread.Sleep(150);
                        }
                    }
                    // 检查是否在战斗中
                    dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                        Thread.Sleep(150);
                    }
                    // 胜利|失败过场
                    dm.FindPic(309, 96, 419, 190, "太鼓图1.bmp|太鼓图2.bmp", "000000", 0.85, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        dm.MoveTo(336 + RandX1, 404 + RandY1);
                        dm.LeftClick();
                        notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                        Thread.Sleep(150);
                    }
                    dm.FindPic(287, 84, 409, 181, "失败太鼓图.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(30, 466);
                        dm.LeftClick();
                        notice.Text = "战斗失败！";
                        Thread.Sleep(150);
                        fail();

                    }
                    // 奖励结算
                    dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp|宝箱7.bmp", "000000", 0.8, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(447 + RandX2, 425 + RandY2);
                        dm.LeftClick();
                        notice.Text = "领取奖励中！...";
                        Thread.Sleep(150);
                        success();
                    }
                    else
                    {
                        dm.FindPic(38, 474, 79, 514, "数据图3.bmp", "000000", 0.8, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(447 + RandX2, 425 + RandY2);
                            dm.LeftClick();
                            notice.Text = "领取奖励中！...";
                            Thread.Sleep(150);
                            success();
                        }
                    }
                    failEnd();
                } while (running && isOk);
            }
            else if (0 < runNumber)
            {
                do
                {
                    //不接协作
                    dm.FindPic(621, 370, 658, 408, "不接协作.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo((int)x, (int)y);
                        dm.LeftClick();
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindStr(676, 372, 746, 404, "拒绝", "b@080a0e-303030|181c25-303030|0b0c12-303030|4b4c52-202020", 0.9, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo((int)x, (int)y);
                            dm.LeftClick();
                            Thread.Sleep(150);
                        }
                    }
                    //点击挑战
                    dm.FindStr(840, 455, 897, 485, "挑战", "b@dbd1b9-404040|552200-000000|d39c53-000000|aa8629-000000|9e7822-000000|f1c87d-000000|d0ae46-000000|9f6c06-000000|a7896b-101010|a49270-000000", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(823 + RandX, 441 + RandY);
                        dm.LeftClick();
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindPic(840, 451, 896, 508, "业原火-痴.bmp", "000000", 0.9, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(823 + RandX, 441 + RandY);
                            dm.LeftClick();
                            Thread.Sleep(150);
                        }
                    }
                    //点击准备
                    dm.FindStr(844, 417, 920, 463, "准备", "b@dbd1b9-404040|e8d0a6-303030", 0.9, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(840 + RandX2, 414 + RandY2);
                        dm.LeftClick();
                        notice.Text = "点击准备中...";
                        Thread.Sleep(150);
                    }
                    else
                    {
                        dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(840 + RandX2, 414 + RandY2);
                            dm.LeftClick();
                            notice.Text = "点击准备中...";
                            Thread.Sleep(150);
                        }
                    }
                    // 检查是否在战斗中
                    dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                        Thread.Sleep(150);
                    }
                    // 胜利|失败过场
                    dm.FindPic(308, 98, 412, 189, "太鼓图.bmp|太鼓图2.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        int amount1 = amount + 1;
                        dm.MoveTo(336 + RandX1, 404 + RandY1);
                        dm.LeftClick();
                        notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                        Thread.Sleep(150);
                    }
                    dm.FindPic(287, 84, 409, 181, "失败太鼓图.bmp", "000000", 0.9, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(30, 466);
                        dm.LeftClick();
                        notice.Text = "战斗失败！";
                        Thread.Sleep(150);
                        fail();

                    }
                    // 奖励结算
                    dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp|宝箱7.bmp", "000000", 0.8, 0, out x, out y);
                    if ((int)x > 0 && (int)y > 0)
                    {
                        dm.MoveTo(447 + RandX2, 425 + RandY2);
                        dm.LeftClick();
                        notice.Text = "领取奖励中！...";
                        Thread.Sleep(150);
                        success();
                    }
                    else
                    {
                        dm.FindPic(38, 474, 79, 514, "数据图3.bmp", "000000", 0.8, 0, out x, out y);
                        if ((int)x > 0 && (int)y > 0)
                        {
                            dm.MoveTo(447 + RandX2, 425 + RandY2);
                            dm.LeftClick();
                            notice.Text = "领取奖励中！...";
                            Thread.Sleep(150);
                            success();
                        }
                    }
                    autoEnd();
                    failEnd();
                } while (running && isOk);
            }
        }


        public void juexing(int rId, object x, object y)
        {
            Random ran = new Random();
            int rk = ran.Next(20, 20);
            int rkx2 = ran.Next(0, 73);
            int rky2 = ran.Next(0, 46);
            int RandX = ran.Next(0, 451);
            int RandY = ran.Next(0, 136);
            int RandX2 = ran.Next(0, 507);
            int RandY2 = ran.Next(0, 109);
            int RandX3 = ran.Next(0, 900);
            int RandY3 = ran.Next(0, 75);
            bool choice = false;
            bool tuodong = false;
            switch (rId)
            {
                case 0:
                    if (0 == runNumber)
                    {
                        do
                        {
                            //检查界面
                            checkMian(x,y);
                            //点击觉醒
                            dm.FindPic(41, 474, 88, 509, "觉醒材料.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo((int)x, (int)y);
                                dm.LeftClick();
                                notice.Text = "点击觉醒中...";
                                Thread.Sleep(150);
                            }
                            //选择对应的觉醒材料
                            dm.FindStr(75, 17, 182, 47, "觉醒之塔", "b@050405-959595", 0.9, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                switch (aFunctionCb.SelectedIndex)
                                {
                                    case 0:
                                        dm.MoveTo(119 + rk, 256+ rk);
                                        dm.LeftClick();
                                        Thread.Sleep(150);
                                        break;
                                    case 1:
                                        dm.MoveTo(344 + rk, 226 + rk);
                                        dm.LeftClick();
                                        Thread.Sleep(150);
                                        break;
                                    case 2:
                                        dm.MoveTo(563 + rk, 215 + rk);
                                        dm.LeftClick();
                                        Thread.Sleep(150);
                                        break;
                                    case 3:
                                        dm.MoveTo(787 + rk, 213 + rk);
                                        dm.LeftClick();
                                        Thread.Sleep(150);
                                        break;
                                }

                            }
                            //拖动
                            dm.FindStr(76, 17, 178, 45, "觉醒材料", "b@050405-909090", 0.9, out x, out y);
                            if (!tuodong && (int)x > 0 && (int)y > 0 )
                            {
                                dm.MoveTo(237, 459);
                                dm.LeftDown();
                                Thread.Sleep(150);
                                dm.MoveTo(232, 123);
                                dm.LeftUp();
                                Thread.Sleep(150);
                                dm.MoveTo(237, 459);
                                dm.LeftDown();
                                Thread.Sleep(150);
                                dm.MoveTo(232, 123);
                                dm.LeftUp();
                                Thread.Sleep(150);
                                tuodong = true;
                            }
                            //选择第十层
                            if(tuodong && !choice)
                            {
                                dm.FindStr(207, 417, 268, 451, "拾层", "b@aaa9ae-303030", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo((int)x, (int)y);
                                    dm.LeftClick();
                                    Thread.Sleep(150);
                                }
                            }
                            if (!choice) {
                                dm.FindStr(207, 417, 268, 451, "拾层", "b@ccb38a-303030", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    tuodong = true;
                                    choice = true;
                                    notice.Text = "选择十层成功！";
                                    Thread.Sleep(150);
                                }
                            }
                            //挑战
                            if (choice)
                            {
                                dm.FindStr(842, 456, 892, 481, "挑战", "b@dcd4bb-303030", 0.9, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo((int)x, (int)y);
                                    dm.LeftClick();
                                    notice.Text = "点击挑战中...";
                                    Thread.Sleep(150);
                                }
                            }
                            //点击准备
                            dm.FindStr(850, 415, 918, 467, "准备", "591410-505050|aa4422-303030", 0.8, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(850 + rkx2, 416 + rky2);
                                dm.LeftClick();
                                notice.Text = "点击准备中...";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(844, 412, 923, 469, "准备1.bmp|准备2.bmp|准备4.bmp|准备5.bmp", "000000", 0.85, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    dm.MoveTo(850 + rkx2, 416 + rky2);
                                    dm.LeftClick();
                                    notice.Text = "点击准备中...";
                                    Thread.Sleep(150);
                                }
                            }
                            // 检查是否在战斗中
                            dm.FindPic(9, 463, 121, 522, "倍速.bmp|自动.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                notice.Text = "正在进行第" + amount1.ToString() + "次战斗！";
                                Thread.Sleep(150);
                            }
                            // 胜利|失败过场
                            dm.FindPic(308, 95, 412, 187, "太鼓图.bmp|太鼓图1.bmp|太鼓图2.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                int amount1 = amount + 1;
                                dm.MoveTo(503 + RandX, 400 + RandY);
                                dm.LeftClick();
                                notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                Thread.Sleep(150);
                            }
                            else
                            {
                                dm.FindPic(285, 416, 329, 459, "数据图.bmp", "000000", 0.9, 0, out x, out y);
                                if ((int)x > 0 && (int)y > 0)
                                {
                                    int amount1 = amount + 1;
                                    dm.MoveTo(503 + RandX, 400 + RandY);
                                    dm.LeftClick();
                                    notice.Text = "第" + amount1.ToString() + "次战斗胜利！";
                                    Thread.Sleep(150);
                                }
                            }
                            dm.FindPic(298, 91, 407, 176, "失败太鼓图3.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(30 + RandX3, 466 + RandY3);
                                dm.LeftClick();
                                notice.Text = "战斗失败！";
                                Thread.Sleep(150);
                                fail();
                            }
                            // 奖励结算
                            dm.FindPic(381, 343, 578, 454, "宝箱1.bmp|宝箱2.bmp", "000000", 0.9, 0, out x, out y);
                            if ((int)x > 0 && (int)y > 0)
                            {
                                dm.MoveTo(447 + RandX2, 425 + RandY2);
                                dm.LeftClick();
                                notice.Text = "领取奖励中！...";
                                Thread.Sleep(150);
                                success();
                            }
                            failEnd();
                        }
                        while (running && isOk);
                    }
                    break;
            }
        }
        //------------------------------------------------------------------------------------------------------------------------
        //下面为通用方法
        //------------------------------------------------------------------------------------------------------------------------
        public static void reset() {
            amount = 0;
            failAmount = 0;
            lastAmountTime = new DateTime();
        }
        public static void end()
        {
            switch (endResult) {
                case 0:
                    form1.notice.Text = "运行成功" + amount.ToString() + "次后自动结束！";
                    break;
                case 1:
                    form1.notice.Text = "运行成功" + amount.ToString() + "次后手动结束！";
                    break;
                case 2:
                    form1.notice.Text = "运行失败" + failAmount.ToString() + "次后自动结束！";
                    break;
            }
            amount = 0;
            failAmount = 0;
            lastAmountTime = new DateTime();
        }

        public static void success()
        {
            if (TimeAccount.GetTimeDiffer1(lastAmountTime))
            {
                amount++;
                lastAmountTime = DateTime.Now;
            }
        }

        public static void fail()
        {
            if (TimeAccount.GetTimeDiffer1(lastFailAmountTime))
            {
                failAmount++;
                lastFailAmountTime = DateTime.Now;
            }
        }

        public static void failEnd()
        {
            if (failAmount >= failNumber)
            {
                endResult = 2;
                running = false;
            }
        }

        public static void autoEnd()
        {
            if (amount >= runNumber)
            {
                endResult = 0;
                running = false;  
            }
        }
        //------------------------------------------------------------------------------------------------------------------------
        //下面为游戏界面检查（检查目前停留在哪个界面）
        //------------------------------------------------------------------------------------------------------------------------

        public void checkMian(object x, object y)
        {
            dm.FindStr(269, 35, 293, 68, "加成", "b@fbc171-404040|f47c5d-303030", 0.9, out x, out y);
            if ((int)x > 0 && (int)y > 0)
            {
                dm.FindStr(488, 100, 528, 138, "索", "b@fff7b6-404040|fffa36-202020|ffff01-303030|fdee45-303030|ffeead-303030|f0c889-303030", 0.85, out x, out y);
                if ((int)x > 0 && (int)y > 0)
                {
                    dm.MoveTo((int)x, (int)y);
                    dm.LeftClick();
                    notice.Text = "点击探索！";
                    Thread.Sleep(150);
                }
            }
        }


        //------------------------------------------------------------------------------------------------------------------------
        //下面为鉴权的定时任务
        //------------------------------------------------------------------------------------------------------------------------
        public static void IsOkJob()
        {
            StringBuilder str = new StringBuilder(baseUrl);
            string url = str.Append("/user/checkToken?machineCode=" + machineCode).ToString();//鉴权接口
            string html = "";
            HttpHelper http = new HttpHelper();
            HttpItem item = new HttpItem()
            {
                URL = url,
                Method = "post",
                Accept = "application/json, text/plain, */*",
                Postdata = "",
                ContentType = "application/json;charset=UTF-8"
            };
            string codeParse = "";
            if (isOk && !string.IsNullOrEmpty(tokens))
            {
                item.Header.Add("Accept-Encoding", "gzip, deflate, br");
                item.Header.Add("Accept-Language: zh-CN,zh;q=0.9");
                item.Header.Add("sec-ch-ua-platform: 'Windows'");
                item.Header.Add("Authorization:Bearer " + tokens.Trim());
                HttpResult result = http.GetHtml(item);
                html = result.Html;
                codeParse = HttpHelper.JsonParse(html, "code");
                if (null != codeParse && codeParse.Equals("200"))
                {
                    string dataParse = HttpHelper.JsonParse(html, "data");
                    if (dataParse.Equals(TextEncryptUtils.Md532(userNameParse + "true")))
                    {
                        isOk = true;
                    }
                    else
                    {
                        endResult = 0;
                        isOk = false;
                        running = false;
                        reset();
                        string userInfo = System.Windows.Forms.Application.StartupPath + "\\userInfo.txt";
                        if (File.Exists(userInfo))  // 判断是否已有相同文件 
                        {
                            File.WriteAllText(userInfo, "");
                        }
                        MessageBox.Show("登录已失效，请重新登录！");
                        Form1.form1.accountLabel.Text = "null";
                        Form1.form1.userTypeLabel.Text = "null";
                        Form1.form1.ETimeLabel.Text = "0000-00-00 00:00:00";
                        Form1.form1.notice.Text = "登录已失效，任务已停止！";
                    }
                }
                else
                {
                    endResult = 0;
                    isOk = false;
                    running = false;
                    reset();
                    string userInfo = System.Windows.Forms.Application.StartupPath + "\\userInfo.txt";
                    if (File.Exists(userInfo))  // 判断是否已有相同文件 
                    {
                        File.WriteAllText(userInfo, "");
                    }
                    MessageBox.Show("登录已失效，请重新登录！");
                    Form1.form1.accountLabel.Text = "null";
                    Form1.form1.userTypeLabel.Text = "null";
                    Form1.form1.ETimeLabel.Text = "0000-00-00 00:00:00";
                    Form1.form1.notice.Text = "登录已失效，任务已停止！";

                }
            }
        }
        //以下是副选择框自动赋值
        private void functionCb_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (functionCb.SelectedIndex.Equals(5))
            {
                aFunctionCb.Items.AddRange(new object[] { "业火轮", "风转符", "水灵鲤", "天雷鼓" });
                aFunctionCb.SelectedIndex = 3;
            }
            else {

                aFunctionCb.Items.Clear();
            }


        }
    }
}
